<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>鼓励金兑现</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" /> 
		<link href="__INDEX__/store/css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="__INDEX__/store/css/style.css" />
		<link rel="stylesheet" href="__INDEX__/store/css/newsj.css" />
	</head>

	<body class="sjindexcon">
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">鼓励金兑现</h1>
		</header>
		<div class="mui-content sjindexcon">
			<div class="tix_numbox">
				<div>兑现额度</div>
				<div class="tix_num">
					<label><span class="iconfont icon-tixian"></span></label>
					<input type="text" placeholder="输入兑现数量" style="font-size: 1.2rem;" onkeyup="key_up(this)" id="much" autocomplete="off" />
				</div>
				<div class="tips">当前鼓励金数量：<em><?php  echo substr($agent_info['score'],0,strlen($agent_info['score'])-2);?></em></div>
			</div>
			<div class="tix_numbox">
				<div>实际到账</div>
				<div class="tix_num">
					<label>¥</label>
					<input type="number" placeholder="0" id="tmuch" autocomplete="off" style="font-size: 1.2rem;" />
				</div>
				<div class="mui-input-row mui-radio mui-left tips xiey">
					<input name="checkbox" id="checkbox" value="Item 1" type="radio" style="margin-left: -20px;" autocomplete="off" />
					<label><a href="#" style="margin-left: -25px;">服务协议</a></label>
				</div>
			</div>
			<div class="btnbox2" style="text-align:center;"><button type="button" class="dzyhq_btn">兑现</button></div>
			<div class="tuig_tips3">即时到账余额钱包</div>
		</div>

	</body>

</html>

<script src="__INDEX__/store/js/mui.min.js"></script>
<script type="text/javascript" src="__INDEX__/store/js/jquery.min.js"></script>
<script type="text/javascript" src="__INDEX__/store/js/layer/layer.min.js"></script>

<script>
	function key_up(obj) {
		obj.value = obj.value.replace(/[^\d]/g, ""); //清除“数字”和“.”以外的字符
		obj.value = obj.value.replace(/^\./g, ""); //验证第一个字符是数字而不是.
		obj.value = obj.value.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的.
		obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
		$("#tmuch").val(parseFloat(obj.value) * 95 / 10000);
	}

	$(".btnbox2").click(function() { 
		score = "{$agent_info['score']}";
		value = $("#much").val();
		if(value == "") {
			layer.msg("请输入兑现数量");
			return;
		}  

		if(value < 1000) {
			layer.msg("兑现数量最少为1000");
			return;

		}

		if(value % 1000 != 0) {
			layer.msg("请输入1000的整数倍");
			return;

		}
		
		if(parseFloat(score) <= parseFloat(value)){
			layer.msg("鼓励金不足");
			return;
		}
		
		if($('#checkbox').is(':checked') == false) {
			layer.msg('请阅读兑现协议');
			return;
		}
		var btnArray = ['我不兑现', '同意兑现'];
		mui.confirm('1  鼓励金余额满400以上方可操作兑现。<br/>2  兑现成功，即时扣掉5%服务费。 ', '鼓励金兑换须知', btnArray, function(e) {
			if(e.index == 1) {
				$.ajax({
					type: 'post',
					url: "{:url('agent/score_yue')}",
					data: {
						value: value
					},
					success: function(data) { 
						if(data.code == 200) {
							layer.msg(data.msg,{
									icon: 1,
									time: 1000
								},function() {
								window.location.href = "{:url('agent/score_record')}";
							});

						} else {
							layer.msg(data.msg, {
									icon: 1,
									time: 1000
								});
							console.log(data.msg);
						}
					}
				})
			}
		})
	})
</script>